﻿
var webset = new Object();//站点配置信息
webset.domain = "https://t.slxt.net";//微信站点域名
webset.buspath = "/dkb";//业务站点根目录
webset.busgourl = "/dkbui/index.html";//业务站点入口地址(微信登录成功页)
webset.shareurl = "/dkbui/login.html";//分享url(一般为微信发起登录页)
webset.sharelogourl = "/dkbui/img/logo.png";//分享图标
webset.apipath = "/api";//微信服务接口站点名(无特殊情况，无需改动)
webset.apiloginurl = "/entry.aspx";//微信服务接口站点入口地址(无特殊情况，无需改动)

//清除浏览器url历史记录
function ClearHistory() {
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            window.history.pushState('forward', null, '#');
            window.history.forward(1);
        });
    }
    window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
    window.history.forward(1);
}

function getCookieLZ(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

function setCookieLZ(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function delCookieLZ(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookieLZ(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

function dynamicLoadCss(url) {
    var head = document.getElementsByTagName('head')[0];
    var link = document.createElement('link');
    link.type = 'text/css';
    link.rel = 'stylesheet';
    link.href = url;
    head.appendChild(link);
}

function dynamicLoadJs(url, callback) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    if (typeof (callback) == 'function') {
        script.onload = script.onreadystatechange = function () {
            if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
                callback();
                script.onload = script.onreadystatechange = null;
            }
        };
    }
    head.appendChild(script);
}

//取字符串所占的字节长度（采取将255意外的字符替换成"aa"的做法，取长度）  
function GetStrRealLength(str) {
    return str.replace(/[^\x00-\xff]/g, "aa").length;
}

//验证手机号码
function checkMobile(str) {
    var re = /^1\d{10}$/;
    var result = str.match(re);
    if (result == null) return false;
    return true;
}

//验证电话号码
function checkPhone(strPhone) {
    var phoneRegWithArea = /^[0][1-9]{2,3}-?[0-9]{5,10}$/;
    var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/;
    if (strPhone.length > 8) {
        if (phoneRegWithArea.test(strPhone)) {
            return true;
        } else {
            return false;
        }
    } else {
        if (phoneRegNoArea.test(strPhone)) {
            return true;
        } else {
            return false;
        }
    }
}

//验证联系电话
function IsMobileOrPhone(str) {
    if (checkMobile(str)) {
        return true;
    }
    else {
        if (checkPhone(str)) return true;
    }
    return false;
}

function isNumberOr_Letter(s) {//判断是否是数字或字母或下划线
    var regu = "^[0-9a-zA-Z\_]+$";
    var re = new RegExp(regu);
    if (re.test(s)) {
        return true;
    } else {
        return false;
    }
}


//格式化日期时间
function DateStrFormat(str, deleteMin) {
    try {
        var arr = str.split('T');
        if (deleteMin) {
            str = arr[0];
        }
        else {
            var arrm = arr[1].split('.');
            str = arr[0] + ' ' + arrm[0];
        }
    }
    catch (e) { }
    return str;
}

//验证是否是整数
function isInteger(str) {
    var regu = /^[-]{0,1}[0-9]{1,}$/;
    return regu.test(str);
}

//验证是否是正整数
function isNumber(s) {
    var regu = "^[0-9]+$";
    var re = new RegExp(regu);
    if (s.search(re) != -1) {
        return true;
    } else {
        return false;
    }
}

//验证是否为空
function isNull(str) {
    if (str == "") return true;
    var regu = "^[ ]+$";
    var re = new RegExp(regu);
    return re.test(str);
}

//数组去重
function RemoveDuplicated(arr) {
    var tmp = {},
        ret = [];
    for (var i = 0, j = arr.length; i < j; i++) {
        if (!tmp[arr[i]]) {
            tmp[arr[i]] = 1;
            ret.push(arr[i]);
        }
    }
    return ret;
}

//数组拼接为,字符串
function ChangeArrayToString(arr) {
    var s = '';
    for (var i = 0, j = arr.length; i < j; i++) {
        s += arr[i] + ',';
    }
    s = s.substring(0, s.length - 1);
    return s;
}

function getElementStyle(id, styleName) {
    if ($(id).currentStyle) {//ie 
        return $(id).currentStyle[styleName];
    } else { //ff 
        var $arr = $(id).ownerDocument.defaultView.getComputedStyle($(id), null);
        return $arr[styleName];
    }
}

function getElementStyles(id) {
    if ($(id).currentStyle) {//ie 
        return $(id).currentStyle;
    } else { //ff 
        var $arr = $(id).ownerDocument.defaultView.getComputedStyle($(id), null);
        return $arr;
    }
}


function GetInHtmlMarkStr(s) {
    if (s == undefined || s == null || s == "") {
        return "";
    }
    return html_encode(s);
}

function html_encode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&/g, "&amp;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    s = s.replace(/ /g, "&nbsp;");
    s = s.replace(/\'/g, "&apos;");
    s = s.replace(/\"/g, "&quot;");
    s = s.replace(/\n/g, "<br/>");
    return s;
}


function html_decode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&amp;/g, "&");
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/&apos;/g, "\'");
    s = s.replace(/&quot;/g, "\"");
    s = s.replace(/<br\/>/g, "\n");
    return s;
}


//验证小数
function isDecimal(str) {
    var re = /^(-?\d+)(\.\d+)?$/;
    return re.test(str);
}

//对象装换为字符串
function GetStringLZ(obj) {
    try {
        return obj.toString();
    } catch (e) {
        return '';
    }
}

//获取url参数对象			
function GetRequestLZ() {
    var url = location.search; //获取url中"?"符后的字串  
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

//判断浏览器是否 是竖屏
function isVerticalScreen() {
    var browser = {
        versions: function () {
            var u = navigator.userAgent,
                app = navigator.appVersion;
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
                weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
                qq: u.match(/\sQQ/i) == " qq" //是否QQ
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }

    //判断是否移动端
    if (browser.versions.mobile || browser.versions.android || browser.versions.ios) {
        //alert("移动端"); 
        return true;
    } else {
        var ww = jQuery(window).width();
        var wh = jQuery(window).height();
        if (wh > ww) {
            return true;
        }
    }
    return false;
}

